<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>VUE butten</title>
</head>
<body>
    <!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
</head>
<style>
    html,body{
        margin: 0;
        padding: 0;
    }
    .switchBox{
        transition: all 0.2s;
        margin:100px auto;
        width: 60px;
        height: 30px;
        background-color: rgb(247, 241, 241);
        border: 2px solid #20e820;
        border-radius: 15px;
        overflow: hidden;
    }

    .switchBox.active{
        background-color: rgb(4, 190, 2);
    }
    .switchIcon{
        transition: all 0.2s;
        float: left;
        width: 26px;
        height: 26px;
        background-color: aliceblue;
        border-radius: 13px;
        margin-top: 2px;
        margin-left: 2px;
    }
    .switchBox.active .switchIcon{
        margin-left: 32px;
    }
</style>
<body>
    <div id="app">
        <myswitch :checked="true"></myswitch>
    </div>
</body>

</html>

<script>

    Vue.component('myswitch', {
        props:['checked'],
        data: function () {
            return {
                active:false
            }
        },
        methods:{
            change(){
                this.active=!this.active
                console.log('sucess')
            }
        },
        created(){
            this.active = this.checked

        },
        template: '<div @click="change"   :class="{switchBox:true,active:active}"><div class="switchIcon"></div></div>'
    })
    

    var app = new Vue({
        el: '#app',
        data: {
            message: 'Hello Vue!'
        }
        })
</script>
</body>
</html>